<template>
  <el-row class="my-table">
    <el-button type="primary" size="mini" @click="controlColumns" v-if="showColSelect">列显示隐藏</el-button>
    <el-row>
      <!-- height -16是因为容器padding做了调整 -->
      <el-table border :key="key" :stripe="stripe" :data="tableData" :ref="refName" style="width: 100%" empty-text="暂无数据" tooltip-effect="light" :row-class-name="tableRowClassName" :show-summary="showsummary" :summary-method="getSummaries" :span-method="arraySpanMethod" :cell-style="cellStyle" :height="height-16" :show-header="showHeader" :highlight-current-row="current" @current-change="handleCurrentChange" @sort-change="SortChange" @row-click="rowClick" @row-dblclick="rowDblClick" @select="handleSelectChange" @select-all="handleSelectAllChange" @selection-change="handleSelectionChange" :row-style="rowStyle">
        <el-table-column v-if="ifIndex" type="index" label="序号" width="60" align="center" :fixed="noIsFixed" :index="currIndex"></el-table-column>
        <el-table-column v-if="ifSelect" align="center" :fixed="noIsFixed" type="selection" width="55" :selectable="selectable"></el-table-column>
        <el-table-column v-for="(column, index) in columns" v-if="column.isShow" :prop="column.prop" :key="column.prop" :show-overflow-tooltip="column.hasOwnProperty('tooltip') ? column.tooltip : true" :width="column.width" :min-width="column.minWidth" :fixed="column.fixed" :align="column.align" :label="column.label" :sortable="column.sortable">
          <template slot-scope="scope">
            <my-render v-if="column.render" :row="scope.row" :column="scope.column" :render="column.render"></my-render>
            <span v-else>{{scope.row[column.prop]}}</span>
          </template>
          <template v-if="column.children">
            <el-table-column v-for="(columnChildren,index) in column.children" :prop="columnChildren.prop" :key="index" show-overflow-tooltip :width="columnChildren.width" :min-width="columnChildren.minWidth" :fixed="columnChildren.fixed" :align="columnChildren.align" :label="columnChildren.label" :sortable="columnChildren.sortable">
              <template slot-scope="scope">
                <my-render v-if="columnChildren.render" :row="scope.row" :column="scope.column" :render="columnChildren.render"></my-render>
                <span v-else>{{scope.row[columnChildren.prop]}}</span>
              </template>
              <template v-if="columnChildren.children">
                <el-table-column v-for="(columnChildren1,index1) in columnChildren.children" :prop="columnChildren1.prop" :key="index1" show-overflow-tooltip :width="columnChildren1.width" :min-width="columnChildren1.minWidth" :fixed="columnChildren1.fixed" :align="columnChildren1.align" :label="columnChildren1.label" :sortable="columnChildren1.sortable">
                  <template slot-scope="scope">
                    <my-render v-if="columnChildren1.render" :row="scope.row" :column="scope.column" :render="columnChildren1.render"></my-render>
                    <span v-else>{{scope.row[columnChildren1.prop]}}</span>
                  </template>

                  <template v-if="columnChildren1.children">
                    <el-table-column v-for="(columnChildren2,index2) in columnChildren1.children" :prop="columnChildren2.prop" :key="index2" show-overflow-tooltip :width="columnChildren2.width" :min-width="columnChildren2.minWidth" :fixed="columnChildren2.fixed" :align="columnChildren2.align" :label="columnChildren2.label" :sortable="columnChildren2.sortable">
                      <template slot-scope="scope">
                        <my-render v-if="columnChildren2.render" :row="scope.row" :column="scope.column" :render="columnChildren2.render"></my-render>
                        <span v-else>{{scope.row[columnChildren2.prop]}}</span>
                      </template>

                    </el-table-column>
                  </template>

                </el-table-column>
              </template>
            </el-table-column>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-pagination class="flex_xcenter" v-if="totalPage>=0" background :current-page="pageNum" :page-size="pageSize" :page-sizes="pageSizes" @current-change="currentChange" @size-change="handleSizeChange" layout="total, sizes, prev, pager, next, jumper" :total="totalPage" />
    <colnum-is-show :params="colParams" @colChange="colChange"></colnum-is-show>
  </el-row>
</template>

<script>
import ColnumIsShow from '../MyTable/ColumnIsShow.vue'//列显示隐藏控制狂
/*
 * @Description 封装
 * tableData 表格数据
 * columns 表格参数
 * showsummary 合计开关
 * showTotal 是否显示总计
 * tableHj 显示合计总计的JSON数据
 * arraySpanMethod 合并单元格
 * getSummaries 合计函数
 * pageNum 分页
 * pageSize 每页大小
 * totalPage 总页数
 */
export default {
  props: {
    stripe: { type: Boolean, default: true },
    tableData: Array, // 表格数据
    tableHj: Object,
    columns: Array, // 表格参数
    showsummary: Boolean, // 合计开关
    arraySpanMethod: Function, // 合并单元格
    cellStyle: Function, // 单元格的 style 的回调方法
    rowStyle: Function, // 表格行的 style 的回调方法
    height: Number, // 表格高度
    current: Boolean, // 是否可选中表格
    showHeader: { type: Boolean, default: true }, // 默认显示表头
    selectedCurrent: { type: Number, default: 0 }, // 默认选中第几行
    pageNum: { type: Number, default: 1 }, // 分页
    pageSizes: { type: Array, default: () => [20, 50, 80, 100] },
    pageSize: { type: Number, default: 10 }, // 每页大小
    totalPage: { type: Number, default: -1 }, // 总页数
    ifSelect: { type: Boolean, default: false },
    ifIndex: { type: Boolean, default: true },//第一列是否显示序号，默认第一列显示序号
    showTotal: { type: Boolean, default: false }, // 是否显示总计
    noIsFixed: {
      // 序号是否固定在左侧 默认固定
      type: Boolean,
      default: false
    },
    refName: { type: String, default: 'singleTable' },
    showColSelect: {
      type: Boolean,
      default: false//是否显示配置列显示隐藏弹框
    }
  },
  components: {
    ColnumIsShow
  },
  data () {
    return {
      list: [], // 表格
      colParams: {
        columns: [],
        visible: false//
      },
      key: 1000
    };
  },
  created () {
    this.columns.forEach((el, index) => {
      const prop = this.columns[index].prop ? this.columns[index].prop : this.columns[index].label + 'xxx'
      this.$set(this.columns, index, { ...this.columns[index], prop, isShow: true })
    })
    //初始化给显示隐藏列的数组传值
    const array = []
    this.columns.forEach(el => {
      const { label, prop } = el
      array.push({
        label,
        prop,
        isShow: true
      })
    })
    this.colParams.columns = array
  },
  methods: {
    //打开列控制弹窗
    controlColumns () {
      this.colParams.visible = true
    },
    colChange (data) {
      //列改变
      data.forEach(el => {
        const index = this.columns.findIndex(item => item.prop == el.prop)
        // console.log(index)
        if (index >= 0) {
          //   this.columns[index].isShow = el.isShow
          this.$set(this.columns, index, { ...this.columns[index], isShow: el.isShow })
        }
      })
      this.key = Math.random()
      // setTimeout(() => {
      //     this.$nextTick(() => {
      //         if (this.refName) {
      //             this.$refs[this.refName].doLayout();
      //         } else {
      //             this.$refs.singleTable.doLayout();
      //         }
      //     })
      // }, 500);


    },
    tableRowClassName ({ row, rowIndex }) {
      row.index = rowIndex;
    },
    currentChange (val) {
      // 获取页码
      this.$emit('onCurrentChange', val);
    },
    handleSizeChange (val) {
      // 每页数量
      this.$emit('onPageSizeChange', val);
    },
    // 选中表格
    handleCurrentChange (val) {
      this.$emit('onRowSelectedChange', val);
    },
    // 排序
    SortChange (val) {
      this.$emit('onSortChange', val);
    },
    // 单机某一行
    rowClick (val) {
      this.$emit('onRowClick', val);
    },
    // 双击某一行
    rowDblClick (val) {
      this.$emit('onRowDblClick', val);
    },
    handleSelectionChange (val) {
      this.$emit('onSelectionChange', val);
    },
    handleSelectChange (selection, row) {
      this.$emit('onSelect', selection, row);
    },
    handleSelectAllChange (selection) {
      this.$emit('onSelectAll', selection);
    },
    getSummaries (params) {
      var start = 0;
      var arr = [];
      if (this.showTotal) {
        arr[start] = (
          <div style="margin:0 -10px;">
            <p style="margin:0;padding:0;border-bottom: 1px solid #EBEEF5">
              本页合计
            </p>
            <p style="margin:0;padding:0;border-bottom: 1px solid #EBEEF5">
              总计
            </p>
          </div>
        );
        if (this.ifSelect) {
          start += 1;
          arr[start] = '';
        }
      } else {
        arr[start] = '合计';
        if (this.ifSelect) {
          start += 1;
          arr[start] = '';
        }
      }
      let index = start;
      this.columns.forEach(val => {
        // console.log(val, val.isShow, 'val')
        const { isShow } = val

        if (val.children) {
          val.children.forEach(item => {
            // index++;
            // if (item.isSummaries) {
            //     if (this.tableHj) {
            //         if (this.showTotal) {
            //             arr[index] = (
            //                 <div style="margin:0 -10px;">
            //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
            //                         {this.$utils.parseToThousandth(
            //                             this.tableHj[item.Summaries]
            //                         )}
            //                         &nbsp;
            //                     </p>
            //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
            //                         {this.$utils.parseToThousandth(
            //                             this.tableHj[
            //                                 'zj_' +
            //                                     item.Summaries +
            //                                     '_zj'
            //                             ]
            //                         )}
            //                         &nbsp;
            //                     </p>
            //                 </div>
            //             );
            //         } else {
            //             arr[index] = this.$utils.parseToThousandth(
            //                 this.tableHj[item.Summaries]
            //             );
            //         }
            //     }
            // }
            if (item.children) {
              item.children.forEach(item1 => {
                // index++;
                // if (item1.isSummaries) {
                //     if (this.tableHj) {
                //         if (this.showTotal) {
                //             arr[index] = (
                //                 <div style="margin:0 -10px;">
                //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                //                         {this.$utils.parseToThousandth(
                //                             this.tableHj[item1.Summaries]
                //                         )}
                //                         &nbsp;
                //                     </p>
                //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                //                         {this.$utils.parseToThousandth(
                //                             this.tableHj[
                //                                 'zj_' +
                //                                     item1.Summaries +
                //                                     '_zj'
                //                             ]
                //                         )}
                //                         &nbsp;
                //                     </p>
                //                 </div>
                //             );
                //         } else {
                //             arr[index] = this.$utils.parseToThousandth(
                //                 this.tableHj[item1.Summaries]
                //             );
                //         }
                //     }
                // }
                if (item1.children) {
                  item1.children.forEach(item2 => {
                    // index++;
                    // if (item2.isSummaries) {
                    //     if (this.tableHj) {
                    //         if (this.showTotal) {
                    //             arr[index] = (
                    //                 <div style="margin:0 -10px;">
                    //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                    //                         {this.$utils.parseToThousandth(
                    //                             this.tableHj[item2.Summaries]
                    //                         )}
                    //                         &nbsp;
                    //                     </p>
                    //                     <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                    //                         {this.$utils.parseToThousandth(
                    //                             this.tableHj[
                    //                                 'zj_' +
                    //                                     item2.Summaries +
                    //                                     '_zj'
                    //                             ]
                    //                         )}
                    //                         &nbsp;
                    //                     </p>
                    //                 </div>
                    //             );
                    //         } else {
                    //             arr[index] = this.$utils.parseToThousandth(
                    //                 this.tableHj[item2.Summaries]
                    //             );
                    //         }
                    //     }
                    // }

                    if (item2.children) {
                      item2.children.forEach(item3 => {
                        if (this.showColSelect && !isShow) {

                        } else {
                          index++;
                          if (item3.isSummaries) {

                            if (this.tableHj) {
                              if (this.showTotal) {
                                if(item3.isPercentSummaries) {
                                  arr[index] = (
                                    <div style="margin:0 -10px;">
                                      <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                        {this.$utils.formaterNumberToPercentage(this.tableHj[item3.Summaries], 2)}
                                        &nbsp;
                                      </p>
                                      <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                        {this.$utils.formaterNumberToPercentage(this.tableHj['zj_' + item3.Summaries + '_zj'], 2)}
                                        &nbsp;
                                      </p>
                                    </div>
                                  );
                                } else {
                                  arr[index] = (
                                    <div style="margin:0 -10px;">
                                      <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                        {this.$utils.parseToThousandth(
                                          this.tableHj[item3.Summaries]
                                          , false, this.checkNum(item3.decimalPlaces) ? item3.decimalPlaces : 2)}
                                        &nbsp;
                                      </p>
                                      <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                        {this.$utils.parseToThousandth(
                                          this.tableHj[
                                          'zj_' +
                                          item3.Summaries +
                                          '_zj'
                                            ]
                                          , false, this.checkNum(item3.decimalPlaces) ? item3.decimalPlaces : 2)}
                                        &nbsp;
                                      </p>
                                    </div>
                                  );
                                }
                              } else {
                                if(item3.isPercentSummaries) {
                                  arr[index] = this.$utils.formaterNumberToPercentage(this.tableHj[item3.Summaries], 2);
                                } else {
                                  arr[index] = this.$utils.parseToThousandth(
                                    this.tableHj[item3.Summaries]
                                    , false, this.checkNum(item3.decimalPlaces) ? item3.decimalPlaces : 2);
                                }
                              }
                            }
                          }
                        }

                      })
                    } else {
                      if (this.showColSelect && !isShow) {

                      } else {
                        index++;
                        if (item2.isSummaries) {
                          if (this.tableHj) {
                            if (this.showTotal) {
                              if(item2.isPercentSummaries) {
                                arr[index] = (
                                  <div style="margin:0 -10px;">
                                    <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                      {this.$utils.formaterNumberToPercentage(this.tableHj[item2.Summaries], 2)}
                                      &nbsp;
                                    </p>
                                    <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                      {this.$utils.formaterNumberToPercentage(this.tableHj['zj_' + item2.Summaries + '_zj'], 2)}
                                      &nbsp;
                                    </p>
                                  </div>
                                );
                              } else {
                                arr[index] = (
                                  <div style="margin:0 -10px;">
                                    <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                      {this.$utils.parseToThousandth(
                                        this.tableHj[item2.Summaries]
                                        , false, this.checkNum(item2.decimalPlaces) ? item2.decimalPlaces : 2)}
                                      &nbsp;
                                    </p>
                                    <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                      {this.$utils.parseToThousandth(
                                        this.tableHj[
                                        'zj_' +
                                        item2.Summaries +
                                        '_zj'
                                          ]
                                        , false, this.checkNum(item2.decimalPlaces) ? item2.decimalPlaces : 2)}
                                      &nbsp;
                                    </p>
                                  </div>
                                );
                              }
                            } else {
                              if(item2.isPercentSummaries) {
                                arr[index] = this.$utils.formaterNumberToPercentage(this.tableHj[item2.Summaries], 2);
                              } else {
                                arr[index] = this.$utils.parseToThousandth(
                                  this.tableHj[item2.Summaries]
                                  , false, this.checkNum(item2.decimalPlaces) ? item2.decimalPlaces : 2);
                              }
                            }
                          }
                        }
                      }
                    }
                  })
                } else {
                  if (this.showColSelect && !isShow) {

                  } else {
                    index++;
                    if (item1.isSummaries) {
                      if (this.tableHj) {
                        if (this.showTotal) {
                          if(item1.isPercentSummaries) {
                            arr[index] = (
                              <div style="margin:0 -10px;">
                                <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                  {this.$utils.formaterNumberToPercentage(this.tableHj[item1.Summaries], 2)}
                                  &nbsp;
                                </p>
                                <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                  {this.$utils.formaterNumberToPercentage(this.tableHj['zj_' + item1.Summaries + '_zj'], 2)}
                                  &nbsp;
                                </p>
                              </div>
                            );
                          } else {
                            arr[index] = (
                              <div style="margin:0 -10px;">
                                <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                  {this.$utils.parseToThousandth(
                                    this.tableHj[item1.Summaries]
                                    , false, this.checkNum(item1.decimalPlaces) ? item1.decimalPlaces : 2)}
                                  &nbsp;
                                </p>
                                <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                                  {this.$utils.parseToThousandth(
                                    this.tableHj[
                                    'zj_' +
                                    item1.Summaries +
                                    '_zj'
                                      ]
                                    , false, this.checkNum(item1.decimalPlaces) ? item1.decimalPlaces : 2)}
                                  &nbsp;
                                </p>
                              </div>
                            );
                          }
                        } else {
                          if(item1.isPercentSummaries) {
                            arr[index] = this.$utils.formaterNumberToPercentage(this.tableHj[item1.Summaries], 2);
                          } else {
                            arr[index] = this.$utils.parseToThousandth(
                              this.tableHj[item1.Summaries]
                              , false, this.checkNum(item1.decimalPlaces) ? item1.decimalPlaces : 2);
                          }
                        }
                      }
                    }
                  }
                }
              });
            } else {
              if (this.showColSelect && !isShow) {

              } else {
                index++;
                if (item.isSummaries) {
                  if (this.tableHj) {
                    if (this.showTotal) {
                      if(item.isPercentSummaries) {
                        arr[index] = (
                          <div style="margin:0 -10px;">
                            <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                              {this.$utils.formaterNumberToPercentage(this.tableHj[item.Summaries], 2)}
                              &nbsp;
                            </p>
                            <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                              {this.$utils.formaterNumberToPercentage( this.tableHj['zj_' + item.Summaries + '_zj'], 2)}
                              &nbsp;
                            </p>
                          </div>
                        );
                      } else {
                        arr[index] = (
                          <div style="margin:0 -10px;">
                            <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                              {this.$utils.parseToThousandth(
                                this.tableHj[item.Summaries]
                                , false, this.checkNum(item.decimalPlaces) ? item.decimalPlaces : 2)}
                              &nbsp;
                            </p>
                            <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                              {this.$utils.parseToThousandth(
                                this.tableHj[
                                'zj_' +
                                item.Summaries +
                                '_zj'
                                  ]
                                , false, this.checkNum(item.decimalPlaces) ? item.decimalPlaces : 2)}
                              &nbsp;
                            </p>
                          </div>
                        );
                      }
                    } else {
                      if(item.isPercentSummaries) {
                        arr[index] = this.$utils.formaterNumberToPercentage(this.tableHj[item.Summaries], 2);
                      } else {
                        arr[index] = this.$utils.parseToThousandth(
                          this.tableHj[item.Summaries]
                          , false, this.checkNum(item.decimalPlaces) ? item.decimalPlaces : 2);
                      }
                    }
                  }
                }
              }

            }
          });
        } else {
          if (this.showColSelect && !isShow) {

          } else {
            index++;
            if (val.isSummaries) {
              if (this.tableHj) {
                if (this.showTotal) {
                  if(val.isPercentSummaries) {
                    arr[index] = (
                      <div style="margin:0 -10px;">
                        <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                          {this.$utils.formaterNumberToPercentage(this.tableHj[val.Summaries], 2)}
                          &nbsp;
                        </p>
                        <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                          {this.$utils.formaterNumberToPercentage(this.tableHj['zj_' + val.Summaries + '_zj'], 2)}
                          &nbsp;
                        </p>
                      </div>
                    );
                  } else {
                    arr[index] = (
                      <div style="margin:0 -10px;">
                        <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                          {this.$utils.parseToThousandth(
                            this.tableHj[val.Summaries]
                            , false, this.checkNum(val.decimalPlaces) ? val.decimalPlaces : 2)}
                          &nbsp;
                        </p>
                        <p style="margin:0;padding:0 10px;border-bottom: 1px solid #EBEEF5; white-space:nowrap;overflow:hidden;text-overflow:ellipsis">
                          {this.$utils.parseToThousandth(
                            this.tableHj[
                            'zj_' +
                            val.Summaries +
                            '_zj'
                              ]
                            , false, this.checkNum(val.decimalPlaces) ? val.decimalPlaces : 2)}
                          &nbsp;
                        </p>
                      </div>
                    );
                  }
                } else {
                  if(val.isPercentSummaries) {
                    arr[index] = this.$utils.formaterNumberToPercentage(this.tableHj[val.Summaries], 2);
                  } else {
                    arr[index] = this.$utils.parseToThousandth(
                      this.tableHj[val.Summaries]
                      , false, this.checkNum(val.decimalPlaces) ? val.decimalPlaces : 2);
                  }
                }
              } else {
                let sum = 0;
                if (this.tableData) {
                  this.tableData.map(function (item) {
                    sum += Number(item[val.Summaries]);
                  });
                }
                arr[index] = this.$utils.parseToThousandth(sum);
              }
            }
          }
          // index++;

        }
      });
      return arr;
    },
    checkNum (num) {
      if (num == 0) {
        return true;
      } else {
        return num;
      }
    },
    // 点击当前行，并选中当前行的checkbox
    toggleRowSelection (row) {
      if (this.refName) {
        this.$refs[this.refName].toggleRowSelection(row);
      } else {
        this.$refs.singleTable.toggleRowSelection(row);
      }
    },
    tableDoLyout () {
      if (this.refName) {
        this.$refs[this.refName].doLayout();
      } else {
        this.$refs.singleTable.doLayout();
      }
    },
    /**
     * @method currIndex
     * @description 计算表格中序号
     * @param {number } index 当前序号
     * @return {number} 当前序号
     * @author 柴建锋
     * @date 2020-04-26 16:51:20· 星期天
     * @example
     */
    currIndex (index) {
      return (this.pageNum - 1) * this.pageSize + index + 1;
    },
    setCurrentRow (row) {
      if (row) {
        if (this.refName) {
          this.$refs[this.refName].setCurrentRow(row);
        } else {
          this.$refs.singleTable.setCurrentRow(row);
        }
      }
    },
    renderheader (h, { column, $index }) {
      if (column.property == "qtsfQtSj" && column.label == "其中：其他") {
        return h(
          'el-tooltip',
          {
            props: {
              content: (function () {
                // return <span style="color: red">包括消费税、资源税、城市维护建设税、教育费附加、关税等</span>
                return '包括消费税、资源税、城市维护建设税、教育费附加、关税等'
              })(),
              placement: 'top'
            },
            domProps: {
              innerHTML: column.label + '<span class="el-icon-info"></span>'
            }
          },
          [h('span')]
        )
      }
      return h('span', {
        domProps: {
          innerHTML: column.label
        }
      })
    },
    selectable (row, index) {
      if (row.notCheck === '1') {
        return false;
      } else {
        return true;
      }
    }
  },
  watch: {
    tableData (newvaleu) {
      if (this.refName) {
        // 弹窗展示数据
        setTimeout(() => {
          this.$refs[this.refName].doLayout();
        }, 200);
        this.list = newvaleu;
        // if (!this.ifSelect) {
        // 只有current属性时，点击会有高亮效果，默认选中第一条，有current和ifSelect属性时,点击有高亮，默认不选中第一条
        if (this.selectedCurrent) {
          // 默认选中第几条
          this.$refs[this.refName].setCurrentRow(
            this.list[this.selectedCurrent - 1]
          );
        }
        // }
      } else {
        // 弹窗展示数据
        setTimeout(() => {
          this.$refs.singleTable.doLayout();
        }, 200);
        this.list = newvaleu;
        // if (!this.ifSelect) {
        // 只有current属性时，点击会有高亮效果，默认选中第一条，有current和ifSelect属性时,点击有高亮，默认不选中第一条
        if (this.selectedCurrent) {
          // 默认选中第几条
          this.$refs.singleTable.setCurrentRow(
            this.list[this.selectedCurrent - 1]
          );
        }
        // }
      }
    },
    selectedCurrent (value) {
      if (value) {
        if (this.refName) {
          this.$refs[this.refName].setCurrentRow(this.tableData[value - 1]);
        } else {
          this.$refs.singleTable.setCurrentRow(this.tableData[value - 1]);
        }
      }
    }
  }
};
</script>
<style lang="scss">
.my-table {
  ::v-deep .el-table th {
    background: #f5f5f5;
    font-size: 16px;
    font-weight: 500;
  }
  ::v-deep.flex_xcenter {
    padding: 7px 5px;
    border: 1px solid #ededed;
    border-top: 0;
    background: #f7f7f7;
    .el-input__icon,
    .el-pagination__total,
    .el-pagination__jump,
    .el-pagination__sizes,
    .el-input__inner,
    .btn-prev,
    .btn-next,
    .el-pagination__editor {
      height: 23px;
      line-height: 23px;
    }
    .el-pagination__editor {
      width: 36px;
    }
  }
  ::v-deep .cell {
    line-height: 20px;
  }
  ::v-deep .el-pager li {
    height: 23px;
    line-height: 23px;
  }
}
</style>
